﻿using System.Collections.Generic;
using System.Linq;

namespace PeterKuhn.SilverlightDebugHelper
{
    /// <summary>
    /// Gets the hard-coded settings to use for browser detection.
    /// </summary>
    public class Settings
    {
        /// <summary>
        /// Gets the colleciton of supported browsers.
        /// </summary>
        public IEnumerable<BrowserConfiguration> SupportedBrowsers
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets the collection of selected browsers.
        /// </summary>
        public IList<BrowserConfiguration> SelectedBrowsers
        {
            get;
            private set;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Settings"/> class.
        /// </summary>
        public Settings()
        {
            var browsers = new List<BrowserConfiguration>
                               {
                                   // these are the browsers we understand so far, hard-coded
                                   new BrowserConfiguration(0, "Microsoft Internet Explorer", "iexplore.exe"),
                                   new BrowserConfiguration(1, "Mozilla Firefox", "firefox.exe", "plugin-container.exe"),
                                   new BrowserConfiguration(2, "Google Chrome", "chrome.exe")
                               };

            SupportedBrowsers = browsers;
            SelectedBrowsers = new List<BrowserConfiguration>();
        }

        /// <summary>
        /// Loads the configuration settings.
        /// </summary>
        /// <returns>The loaded configuration settings.</returns>
        public static Settings Load()
        {
            // this is meant to come from a configuration file or similar sometime in the future, if there's demand for it.
            var result = new Settings();
            result.SelectedBrowsers.Add(result.SupportedBrowsers.ElementAt(0));
            result.SelectedBrowsers.Add(result.SupportedBrowsers.ElementAt(1));
            result.SelectedBrowsers.Add(result.SupportedBrowsers.ElementAt(2));
            return result;
        }
    }
}
